testsuite: Fix race in texture-threads test
authorBenjamin Otte <otte@redhat.com>
Thu, 16 Sep 2021 21:56:41 +0000 (23:56 +0200)
committerBenjamin Otte <otte@redhat.com>
Thu, 16 Sep 2021 21:59:37 +0000 (23:59 +0200)
Threads are evil, yo.

testsuite/gdk/texture-threads.c

index 58f631c482b3eba9ba1590f1cff28952decdd4ec..ca970ab3e2611c93f8dfb72bbfc291463d34b579 100644 (file)
@@ -89,20 +89,26 @@ texture_threads (void)
   ensure_texture_access (texture);
   g_assert_nonnull (gdk_gl_context_get_current ());
 
-  /* 4. Run a thread trying to download the texture */
+  /* 4. Acquire the main loop, so the run_in_thread() doesn't
+   * try to acquire it if it manages to outrace this thread.
+   */
+  g_assert_true (g_main_context_acquire (NULL));
+
+  /* 5. Run a thread trying to download the texture */
   loop = g_main_loop_new (NULL, TRUE);
   task = g_task_new (texture, NULL, texture_download_done, loop);
   g_task_run_in_thread (task, texture_download_thread);
   g_clear_object (&task);
 
-  /* 5. Run the main loop waiting for the thread to return */
+  /* 6. Run the main loop waiting for the thread to return */
   g_main_loop_run (loop);
 
-  /* 6. All good */
+  /* 7. All good */
   gsk_renderer_unrealize (gl_renderer);
   g_clear_pointer (&loop, g_main_loop_unref);
   g_clear_object (&gl_renderer);
   g_clear_object (&surface);
+  g_main_context_release (NULL);
 }
 
 int